package com;

import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: BGONZ8
 * Date: 9/24/11
 * Time: 9:31 AM
 * To change this template use File | Settings | File Templates.
 */
public class TestSession {
    private List<ITestCase>  testCases;
    private FeedService fs = null;


    public TestSession()
    {
        testCases = new ArrayList<ITestCase>() ;
        fs = new FeedService();
    }

    public ITestCase addTestCase( ITestCase tc)
    {
        testCases.add(tc);
        tc.setFeedService(fs);
        tc.setTxFile(new TransactionFile());
        return tc;
    }

    public List<ITestCase> getTestCases() {
        return testCases;
    }

    public void setTestCases(List<ITestCase> testCases) {
        this.testCases = testCases;
    }

    public FeedService getFs() {
        return fs;
    }

    public void setFs(FeedService fs) {
        this.fs = fs;
    }

    public String getSessionResult()
    {
        String retval = "";
        for (ITestCase item :testCases )
        {
            retval = retval + item.getResult();
        }
        return retval;
    }

    public void writeToFile() throws Exception
    {

        String fileName = "TestSessionQA" + ".txt";
        String txName = "C:\\packages\\BNX\\Data\\transactionHistory\\" + fileName;
        PrintStream out = null;
        File file = new File(txName);
        if ( file.exists())
        {
            file.delete();
        }

        try {
            out = new PrintStream(new FileOutputStream(txName));
            out.print(getSessionResult());
        }
        catch(Exception e)
        {
            System.out.println("ERROR:" + e.getMessage());
        }
        finally {
            if (out != null) out.close();
        }

    }
}
